package com.xgjweb.init;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xgjweb.common.utils.Constant;

public class InitServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		createFolder();
		//RequestDispatcher rd = request.getRequestDispatcher("flex/index.html");
		//rd.forward(request, response);
		response.sendRedirect("index.html");
	}

	/**
	 * 创建文件夹
	 */
	private void createFolder() {
		File albumfile = new File(Constant.ALBUM_PATH);
		File userPicfile = new File(Constant.PIC_PATH);
		File signfile = new File(Constant.SIGN_PATH);
		File linkfile = new File(Constant.LINK_PATH);
		if (!albumfile.exists()) {
			albumfile.mkdirs();
		}
		if (!userPicfile.exists()) {
			userPicfile.mkdirs();
		}
		if (!signfile.exists()) {
			signfile.mkdirs();
		}
		if (!linkfile.exists()) {
			linkfile.mkdirs();
		}
	}
}
